//
//  YYPVisitorTableViewController.swift
//  YYPWeibo
//
//  Created by youyongpeng on 15/11/21.
//  Copyright © 2015年 youyongpeng. All rights reserved.
//

import UIKit

class YYPVisitorTableViewController: UITableViewController {

    
    // 用户登录标记
    private var userLogin = false // UserAccountViewModel.sharedAccoint.userLogn
    
    // 访客视图
    var visitorView: YYPVisitorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // 判断  如果正确显示 UITableViewController  否则显示 访客视图
        userLogin ? super.loadView() : setUpVisitorView()
        
    }
    
    
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(true)
        
    }
    
    
    // 设置访客视图
    private func setUpVisitorView() {
    
        // 改变根视图
        visitorView = YYPVisitorView()
    
        view = visitorView
        
        // 添加点击事件
        visitorView?.registerButton .addTarget(self, action: "didClickregisterButton", forControlEvents: .TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "didClickLoginButton", forControlEvents: .TouchUpInside)
        
        // 设置导航栏的两头
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "didClickLoginButton")
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "didClickregisterButton")
    }

}

extension YYPVisitorTableViewController {

    func didClickregisterButton() {
        
        print("注册呗")
    }
    
    func didClickLoginButton() {
    
        // 跳转控制器
        let vc = YYPOAuthViewController()
        
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
}
